﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Synergy
{
    public partial class Formscqx : Form
    {


        int i = 0;
        int ksrow;
        int jsrow;
      
        public Formscqx()
        {
            InitializeComponent();
        }

        private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            ksrow = e.RowIndex;
            this.checkBox1.Checked = false;
        }

        private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            jsrow = e.RowIndex;
            this.checkBox1.Checked = false;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            this.progressBar1.Value = 0;
            if (ksrow > jsrow)
            {
                int r;
                r = ksrow;
                ksrow = jsrow;
                jsrow = r;

            }
            for (int i = ksrow; i <= jsrow; i++)
            {
                this.dataGridView1.Rows[i].Cells[1].Value = checkBox1.Checked;
                // this.dataGridView2.Rows[i].Cells[1].Value = checkBox1.Checked;
                if (this.progressBar1.Value >= 99)
                {
                    this.progressBar1.Value = 0;
                }
                else
                {
                    this.progressBar1.Value++;
                }
            }
            this.progressBar1.Value = 100;
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            this.progressBar1.Value = 0;

            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                this.dataGridView1.Rows[i].Cells[1].Value = checkBox2.Checked;

                if (this.progressBar1.Value >= 99)
                {
                    this.progressBar1.Value = 0;
                }
                else
                {
                    this.progressBar1.Value++;
                }
            }

            this.progressBar1.Value = 100;
        }

        private void button_search_Click(object sender, EventArgs e)
        {
            string sql = "  select '' 行号,id id, 权限编号 权限编号,授权人员 授权人员 from [Z_usergn] ";
            System.Data.DataTable tb = pub.U8GetTable(sql);
            if (tb != null)
            {
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    tb.Rows[i]["行号"] = (i + 1).ToString();

                }
            }
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = tb;
            this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            this.dataGridView1.Refresh();
        }

        private void button_print_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {

                if (dataGridView1.Rows[i].Cells[1].EditedFormattedValue.ToString() == "True")
                {
                    string id = this.dataGridView1.Rows[i].Cells["Cid"].Value.ToString();

                    string sql = "    delete from [Z_usergn] where id='" + id + "'   ";

                    pub.ExcuteSql(sql, "id");
                 


                    }
                }

              MessageBox.Show("权限删除成功！", "提示", MessageBoxButtons.OK);
              button_search_Click( sender,  e);
            }
          
        }
    }

